package com.xuetang9.t9.hotel.services.impl;

import com.xuetang9.t9.hotel.beans.OrderFood;
import com.xuetang9.t9.hotel.mapper.IOrderFoodMapper;
import com.xuetang9.t9.hotel.services.IOrderFoodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author pang
 */
@Service
public class OrderFoodServiceImpl implements IOrderFoodService {
    @Autowired
    private IOrderFoodMapper orderFoodMapper;
    @Override
    public int insert(OrderFood orderFood) {
        return orderFoodMapper.insert(orderFood);
    }

    @Override
    public int update(OrderFood orderFood) {
        //更新数量是否等于0，等于就删除该信息
        if(orderFood.getCount() == 0){
            return delete(orderFood.getId(),orderFood.getFoodId());
        }
        return orderFoodMapper.update(orderFood);
    }

    @Override
    public int selectByIdAndFoodId(Integer id, Integer footId) {
        return orderFoodMapper.selectByIdAndFoodId(id,footId);
    }

    @Override
    public int delete(Integer id, Integer footId) {
        return orderFoodMapper.delete(id,footId);
    }
}
